package com.shmn.gongjiajumain.service.impl;

import com.shmn.gongjiajumain.entity.UserEntity;
import com.shmn.gongjiajumain.utils.DateUtil;
import com.shmn.gongjiajumain.vo.ScrapSubmitHistory.ScrapSubmitHistoryTableVo;
import com.shmn.gongjiajumain.vo.people.PeopleTableVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.lang.reflect.Field;
import java.util.*;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.shmn.common.utils.PageUtils;
import com.shmn.common.utils.Query;

import com.shmn.gongjiajumain.dao.ScrapSubmitHistoryDao;
import com.shmn.gongjiajumain.entity.ScrapSubmitHistoryEntity;
import com.shmn.gongjiajumain.service.ScrapSubmitHistoryService;

@Slf4j
@Service("scrapSubmitHistoryService")
public class ScrapSubmitHistoryServiceImpl extends ServiceImpl<ScrapSubmitHistoryDao, ScrapSubmitHistoryEntity> implements ScrapSubmitHistoryService {

    @Override
    public PageUtils queryPage1(ScrapSubmitHistoryEntity scrapSubmitHistory) {
        Map<String, Object> params = new HashMap<>();
        params.put("page",scrapSubmitHistory.getPageIndex());
        params.put("limit",scrapSubmitHistory.getPageSize());

        QueryWrapper<ScrapSubmitHistoryEntity> wrapper = new QueryWrapper<>();
        if (scrapSubmitHistory.getCode() != null){
            wrapper.like("code",scrapSubmitHistory.getCode());
        }
        if (scrapSubmitHistory.getSeqId() != null){
            wrapper.like("seq_id",scrapSubmitHistory.getSeqId());
        }
        if (scrapSubmitHistory.getScrapReason() != null){
            wrapper.like("scrap_reason",scrapSubmitHistory.getScrapReason());
        }
        if (scrapSubmitHistory.getStatus() != null){
            wrapper.eq("status",scrapSubmitHistory.getStatus());
        }
//        if (scrapSubmitHistory.getStartToEndTime() != null){
//            List<String> startToEndTime = scrapSubmitHistory.getStartToEndTime();
//            String startTime = startToEndTime.get(0);
//            String endTime = startToEndTime.get(1);
//            if (startTime != null && endTime != null){
//                wrapper.between("submit_time",startTime,endTime);
//            }else if (startTime != null){
//                wrapper.ge("submit_time",startTime);
//            }else {
//                wrapper.le("submit_time",endTime);
//            }
//        }
        IPage<ScrapSubmitHistoryEntity> page = this.page(
                new Query<ScrapSubmitHistoryEntity>().getPage(params),
                wrapper
        );
        return new PageUtils(page);
    }

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<ScrapSubmitHistoryEntity> page = this.page(
                new Query<ScrapSubmitHistoryEntity>().getPage(params),
                new QueryWrapper<ScrapSubmitHistoryEntity>()
        );

//        PageUtils pageUtils = new PageUtils(page);
//        pageUtils.getList().forEach(item->{
//            ScrapSubmitHistoryTableVo scrapSubmitHistoryTableVo = new ScrapSubmitHistoryTableVo();
//            BeanUtils.copyProperties(item,scrapSubmitHistoryTableVo);
//            scrapSubmitHistoryTableVo.setSubmitTime(DateUtil.formatDate(new Date()));
//        });
        return new PageUtils(page);
    }

}